
*************************************************************************************************************************
******Going "beyond the GDP" in the digital economy: Exploring the relationship between internet use and well-being.******
*************************************************************************************************************************


****************************
*CHOOSE THE RIGHT DIRECTORY
****************************
cd "Your directory"

**********************
**#*DATA PREPARATION*
**********************
*Rounds 8 and 9 from the European Social Suvey (ESS) cab be downloaded from: https://www.europeansocialsurvey.org/data/

*Firstly we have to append the two datasets together ESS8 and ESS9
use ESS8.dta, clear
append using ESS9.dta
save ESS8_9.dta, replace


*It is important to weight data using "anweight" -see "ESS_weighting_data_1_1.pdf" for more info. 
destring anweight, replace
*Keep only Spanish data
keep if cntry=="ES"
count
*Generate variable year -year of the survey-
gen year=.
replace year=2016 if essround==8
replace year=2018 if essround==9
gen r9=(essround==9)
sort year 
by year: count
*Internet related variables: netusoft & netustm -only asked if netusoft==4 OR 5-

*Subjective Wb Variables: happy, stlife sclmeet inprdsc sclact


*GENERATE VARS TO BE USED IN THE MODELS
gen daily_internet=(netusoft>3) //internet use daily or mostly daily
gen internet_time=netustm
gen internetsq = internet_time^2

*Sociodemographics
	**General SWB:
sum happy [aweight = anweight] //How happy are you, from 00 extremely unhappy to 10 extremely happy -77 refulal, 88 don't know.
sum stflife [aweight = anweight] //How satisfied with life as a whole, from 0 extremely dissatisfied to 10 extremely satisfied.

	**Social life:
sum sclmeet [aweight = anweight] //How often socially meet with friends, relatives or colleagues -from 1 never to 7 every day
sum inprdsc [aweight = anweight] // How many people with whom you can discuss intimate and personal matters -from 00 none to 06 10 or more-
sum sclact  [aweight = anweight] // Take part in social activities compared to others of same age -fromm 1 much less to 5 much more-
 
tab health [aweight = anweight] //subjective health: 1 (very good) 5 (very bad)
tab hlthhmp [aweight = anweight] //disability -Hampered in daily activities by illness/disability/infirmity/mental problem-
gen hampered=(hlthhm<3)
gen livingpartner=(rshipa2==1 | rshipa3==1| rshipa4==1| rshipa5==1| rshipa6==1| rshipa7==1| rshipa8==1| rshipa9==1| rshipa10==1| rshipa11==1| rshipa12==1| rshipa13==1| rshipa14==1| rshipa15==1)	
tab marsts [aweight = anweight]
gen hhsize=hhmmb 
gen female=(gndr==2)
label define fem 0 "Male" 1 "Female"
label values female fem
tab eisced [aweight = anweight]  //highest level of education isced (there is also edulvlb which is an harmonised variable gen from ctry specific vars, it has more categories)
gen employed=pdwrk //Dummy 1 working 0 not working
gen hhdecile=hinctnta //household income decile: subjetive 
sum hhdecile
gen old60=(agea>60)
gen sqage = agea^2


*Include internet speed data:
merge m:1 region using speed.dta
drop _merge

*Recode deciles to take acount dk/da
gen decile_r=(hhdecile>5)
replace decile_r=2 if hhdecile==.a |hhdecile==.b| hhdecile==.c
tab decile_r
label define decil 0 "at most 5th decile" 1 "more than 5th decile" 2 "dk/da"

*Generate dummy variables
gen rural=(domicil>3) //living country village or home in countryside
gen badhealth=(health>2) //fair bad and very bad health
gen badhincfel=(hincfel>2) // difficult/very difficult on present income
tab rural
gen more_5decile=(decile_r==1) // Richest 50%


************************************************
**DESCRIPTIVES TO CONSTRUCT TABLE II**

tab daily_internet [aweight = anweight]
sum internet_time [aweight = anweight]

tabstat happy stflife sclmeet inprdsc sclact [aweight = anweight] , stat(mean n)
tabstat happy stflife sclmeet inprdsc sclact [aweight = anweight] if daily_internet==1, stat(mean n)

tabstat female employed agea old60 livingpartner badhealth hampered rural [aweight = anweight] , stat(mean n)
tabstat female employed agea old60 livingpartner badhealth hampered rural [aweight = anweight] if daily_internet==1, stat(mean n)

tab decile_r [aweight = anweight]
tab decile_r [aweight = anweight] if daily_internet==1
tabstat more_5decile  lowedu mededu highedu [aweight = anweight] , stat(mean)

tab domicil [aweight = anweight], 
tab domicil [aweight = anweight] if daily_internet==1

tab hincfel [aweight = anweight]
tab hincfel [aweight = anweight] if daily_internet==1

tabstat eisced [aweight = anweight], stat(mean n)
tabstat eisced [aweight = anweight] if daily_internet==1, stat(mean n) 

tab r9 [aweight = anweight]
tab r9 [aweight = anweight] if daily_internet==1


************************************************
*PAIRWISE CORRELATIONS- TABLE III
pwcorr internet_time happy stflife sclmeet inprdsc sclact [aweight = anweight], sig


******************************************************************************
*MODELS OF THE PAPER - Tables IV & V

cmp setup
global x1 "agea eisced employed i.decile_r rural r9 max"
global x1_t "agea eisced i.decile_r rural  r9"
global x1_wb "badhealth hampered hampered##c.internet_time livingpartner female female##c.internet_time agea old60##c.internet_time employed i.domicil i.hincfel r9" 

cmp (stflife= $x1_wb internet_time internetsq) (internet_time= $x1_t ) (daily_internet=$x1) [aweight = anweight], ind($cmp_oprobit daily_internet $cmp_probit ) nonrtolerance vce(robust)
estimates store t1
cmp (happy= $x1_wb internet_time internetsq) (internet_time= $x1_t ) (daily_internet=$x1) [aweight = anweight], ind($cmp_oprobit daily_internet $cmp_probit) nonrtolerance vce(robust)
estimates store t2
cmp (sclmeet= $x1_wb internet_time internetsq) (internet_time= $x1_t ) (daily_internet=$x1) [aweight = anweight], ind($cmp_oprobit daily_internet $cmp_probit) nonrtolerance vce(robust)
estimates store t3
cmp (inprdsc= $x1_wb internet_time internetsq) (internet_time= $x1_t ) (daily_internet=$x1) [aweight = anweight], ind($cmp_oprobit daily_internet $cmp_probit) nonrtolerance vce(robust)
estimates store t4
cmp (sclact= $x1_wb internet_time internetsq) (internet_time= $x1_t ) (daily_internet=$x1) [aweight = anweight], ind($cmp_oprobit daily_internet $cmp_probit) nonrtolerance vce(robust)
estimates store t5
outreg2 [t*] using cmp_3qINTtimesq.xls, replace dec(4) alpha(0.01, 0.05, 0.1) label




****************************************************************************
*MODELS TO CHECK THE VALIDITY OF THE INSTRUMENT - TABLES A1 & A2 IN THE APPENDIX SECTION
cmp setup
global x1 "agea eisced employed i.decile_r rural r9 max"
global x1_t "agea eisced i.decile_r rural r9 max"
global x1_wb "badhealth hampered hampered##c.internet_time livingpartner female female##c.internet_time agea old60##c.internet_time employed i.domicil i.hincfel r9  max " 

cmp (stflife= $x1_wb internet_time internetsq) (internet_time= $x1_t ) (daily_internet=$x1) [aweight = anweight], ind($cmp_oprobit daily_internet $cmp_probit ) nonrtolerance vce(robust)
estimates store iv1
cmp (happy= $x1_wb internet_time internetsq) (internet_time= $x1_t ) (daily_internet=$x1) [aweight = anweight], ind($cmp_oprobit daily_internet $cmp_probit) nonrtolerance vce(robust)
estimates store iv2
cmp (sclmeet= $x1_wb internet_time internetsq) (internet_time= $x1_t ) (daily_internet=$x1) [aweight = anweight], ind($cmp_oprobit daily_internet $cmp_probit) nonrtolerance vce(robust)
estimates store iv3
cmp (inprdsc= $x1_wb internet_time internetsq) (internet_time= $x1_t ) (daily_internet=$x1) [aweight = anweight], ind($cmp_oprobit daily_internet $cmp_probit) nonrtolerance vce(robust)
estimates store iv4
cmp (sclact= $x1_wb internet_time internetsq) (internet_time= $x1_t ) (daily_internet=$x1) [aweight = anweight], ind($cmp_oprobit daily_internet $cmp_probit) nonrtolerance vce(robust)
estimates store iv5
outreg2 [iv*] using cmp_3instrument2.xls, replace dec(4) alpha(0.01, 0.05, 0.1) label




